<?php
//The next comment block is for PHPDocumentor
/**
 * Conference Registration - Registration for conferences
 * 
 * blocks functions:
 * functions for various blocks
 * 
 * @author Kevin van Haaren (kevin@vanhaaren.net)
 * @copyright 2006 Kevin van Haaren, US
 * @package CONFREG
 * @subpackage User_Function
 * 
 */

/**
 * @global Xoops options handler
 * @global Xoops user handler
 * @global Xoops Smarty template handler
 */

// get language constants
include_once XOOPS_ROOT_PATH.'/modules/confreg/language/'.$xoopsConfig['language'].'/main.php';
include_once XOOPS_ROOT_PATH.'/modules/confreg/include/functions.inc';

function b_confreg_summary($options)
{
	global $xoopsDB;

	$conf_id = $options[0];
	
	$block = array();

	$confHdl = $xoopsDB->query(	'SELECT *' .
								' FROM ' . $xoopsDB->prefix("confreg_conferences") . 
								' WHERE confid=' . $conf_id);

	$confData = $xoopsDB->fetchArray($confHdl);
	$block['confData'] = $confData;

	return $block;
}

function b_confreg_stats_show($options)
{
	global $xoopsDB;
	$conf_id = intval($options[0]);
	$block = array();

	$block['extra_name'] = getWorkshopNames($conf_id);

	foreach($block['extra_name'] as $idx => $thisShop) {
		$block['extra_count'][$idx] = 0;
	}

	$confHdl = $xoopsDB->query(	'SELECT *, DATEDIFF(DATE(end_date), DATE(start_date)) as day_count' .
								' FROM ' . $xoopsDB->prefix('confreg_conferences') .
								' WHERE conf_id=' . $conf_id);
	$confData = $xoopsDB->fetchArray($confHdl);
	$block['conf_title'] = $confData['title'];
	
	for ($i = 0; $i <= intval($confData['day_count']); $i++) {
		$block['datename'][] = strftime('%a %b %e, %Y', strtotime( $confData['start_date'] . " +" . $i . " days" ));
		$block['datecount'][] = 0;
	}

	$groupHdl = $xoopsDB->query('SELECT group_id' .
								' FROM ' . $xoopsDB->prefix('confreg_groups') .
								' WHERE conf_id=' . $conf_id );
	$block['total_count'] = 0;
	while ($thisGroup = $xoopsDB->fetchArray($groupHdl)) {
		$userHdl = $xoopsDB->query('SELECT user_id,days_attending' .
									' FROM ' . $xoopsDB->prefix('confreg_people') .
									' WHERE group_id=' . intval($thisGroup['group_id']) );

		while ($thisUser = $xoopsDB->fetchArray($userHdl)) {
			$block['total_count']++;
			foreach ($block['datename'] as $index => $thisDate) {
				if (stripos($thisUser['days_attending'], $thisDate) !== false) {
					$block['datecount'][$index]++;
				}
			}

			$extraHdl = $xoopsDB->query('SELECT extra_id, guests' .
										' FROM ' . $xoopsDB->prefix('confreg_extra_reservations') .
										' WHERE user_id=' . intval($thisUser['user_id']) );
			while ($thisExtra = $xoopsDB->fetchArray($extraHdl)) {
				$block['extra_count'][$thisExtra['extra_id']]++;
			}
		}
	}
	return $block;
}

function b_confreg_edit($options) {
	global $xoopsDB;

	// put quotes here to make query a bit easier to read
	$right_now = "'" . mktime() . "'";
	$confHdl =& $xoopsDB->query('SELECT conf_id, title' .
								' FROM ' . $xoopsDB->prefix('confreg_conferences') .
								' WHERE ((reg_start <= FROM_UNIXTIME(' . $right_now . '))' .
								' AND (reg_end >= FROM_UNIXTIME(' . $right_now . ')))');
	
	$form = '';
	$index = 0;
	while ($result = $xoopsDB->fetchArray($confHdl)) {
		$form .= "<input type='radio' name='options[]' value='" . $result['conf_id'] . "' ";
		if ($result['conf_id'] == $options[0]) {
			$form .= 'checked ';
		}
		$form .= ">" . $result['title'] . '<br />';
	}

	return $form;
}

?>